<template>
  <div class="app-container form_body2">

<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <!-- <el-tag style="margin-left:20px;">*当前账号:</el-tag><span style="color:#868686"> {{mobile}}</span>
      <div class='hrinfo_box'></div> -->
  <el-form-item label="新密码" prop="password">
    <el-input v-model="ruleForm.password"></el-input>
  </el-form-item>
  
  <el-form-item label="确认新密码" prop="newpassword">
    <el-input v-model="ruleForm.newpassword"></el-input>
  </el-form-item>
 

 
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">立即修改</el-button>
  
  </el-form-item>
</el-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      ruleForm: {
        password: '',
        newparssword: ''
      },
      mobile: '123',
      rules: {
        password: [
          {
            required: true,
            min: 3,
            max: 255,
            message: '请输入密码',
            trigger: 'blur'
          },
          {
            min: 3,
            max: 255,
            message: '长度在 3 到 255 个字符',
            trigger: 'blur'
          }
        ],
        newpassword: [
          {
            required: true,
            min: 3,
            max: 255,
            message: '请输入密码',
            trigger: 'blur'
          },
          {
            min: 3,
            max: 255,
            message: '长度在 3 到 255 个字符',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  methods: {
    submitForm(formName) {
      var that = this
      if (that.ruleForm.password != that.ruleForm.newpassword) {
        that.$message({ message: '密码不匹配!', type: 'warning' })
        return
      }
      this.$refs[formName].validate(valid => {
        if (valid) {
          const data = {
            password: that.ruleForm.password
          }
          that
            .$request({
              url: '/admin/updatepassword',
              method: 'post',
              data
            })
            .then(res => {
              if (res.code == 200) {
                that.$message({ message: '修改成功!', type: 'success' })
                that.ruleForm.password = ''
                that.ruleForm.newpassword = ''
              }
            })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>
<style  scoped>


.form_body2 {
  width: 420px;
  height: auto;
}
.hrinfo_box{
    height: 20px;
    width: 100%;
}

</style>
